<?php
class UserCenterAction extends LoginFilterAction {

	
	public function index() {		
		$this->commonOrderCountQuery();
		//查询购物车数量
		$condition_shopping['user_name'] = $_SESSION[C('USER_AUTH_KEY')] ;
		$shoppingCount = count($this->simpleQuery($condition_shopping,'shoppingcart',0));		
		$this->assign('shoppingCount',$shoppingCount) ;
		$this->assign('user_name',$_SESSION[C('USER_AUTH_KEY')]) ;
		
		//热销产品
		$this->getsalesamountList();
		//最新上架
		$this->getlastUpdateList();		
		$this->display();
	}
	
	
	private function commonOrderCountQuery(){
		//查询未完成订单数量
		$condition_order_no['user_name'] = $_SESSION[C('USER_AUTH_KEY')] ;
		$condition_order['status'] = 1 ;
		$noComplete =  count($this->simpleQuery($condition_order,'user_order',0));
		
		
		//查询已完成订单数量
		$condition_order_yes['user_name'] = $_SESSION[C('USER_AUTH_KEY')] ;
		$condition_order_yes['status'] = 0 ;
		$yesComplete =  count($this->simpleQuery($condition_order_yes,'user_order',0));
		
		$finalCount = $noComplete + $yesComplete ;
		
		$this->assign('noComplete',$noComplete) ;
		$this->assign('yesComplete',$yesComplete) ;
		$this->assign('finalCount',$finalCount) ;
	}
	
	public function userOrder(){
		$this->commonOrderCountQuery();
		/*
		$queryString_order = "select a.order_id,b.`name`,a.status,a.totlecount,a.createdate,a.`status` from user_order a , product b 
									where instr( a.product_id_list,b.id) and a.user_name = '" .$_SESSION[C('USER_AUTH_KEY')]. "'";*/
		$queryString_order = "select * from user_order where user_name = '" .$_SESSION[C('USER_AUTH_KEY')]. "' order by createdate desc" ;			
		$this->assign("orderList",$this->CommonSimplequery(1,$queryString_order ,'' ,'' ,0,""));
		$this->display() ;
	}
	
	
	public function userOrderDetail(){
		
		$orderConditon['order_id'] = $_REQUEST ['id'] ;
		$order = $this->simpleQuery($orderConditon, 'user_order' , 1 );
		
		$this->assign('orderVo',$order) ;
		/*
		$queryString_proList = "select * from product where status =1  and id  in ('" .$order['product_id_list']. "') order by statusdate desc  ";			
		$this->assign("proList",$this->CommonSimplequery(1,$queryString_proList ,'' ,'' ,0,""));
		*/
		
		$this->display();
	}
	
	
	
	public function userInfomation(){
		$condition_user['name'] = $_SESSION[C('USER_AUTH_KEY')] ;		
		$this->assign('userVo',$this->simpleQuery($condition_user,'loginuser',1));		
		$this->display() ;
	}
	
	public function userInfomationUpdate(){
		
		$Dao = M("loginuser");	
	    // 需要更新的数据
		
	    $data['pwd'] = $_REQUEST ['pwd'] ;
	    $data['realname'] = $_REQUEST ['realname'] ;
	    $data['email'] = $_REQUEST ['email'] ;   	
	    $data['mobile'] = $_REQUEST ['mobile'] ;   	
	    $data['address'] = $_REQUEST ['address'] ;   	   	
	    $data ["statusdate"] = date('Y-m-d H:i:s',time());
	    // 更新的条件
	    $condition['id'] = $_REQUEST ['id'];
	    $result = $Dao->where($condition)->save($data);
		
		if ($result==false){
			$msg = "个人资料修改失败！" . $model->getError();
		}else{
			$msg = "个人资料修改成功！";
		}
		$this->ajaxReturn ( "111111", $msg, 1 );		
	}
	


}
?>